# -*- encoding: utf-8 -*-
from . import FixtureTest


class BuildingMergingTest(FixtureTest):

    def test_sao_paulo(self):
        import dsl
        from shapely.wkt import loads as wkt_loads

        z, x, y = (15, 12132, 18590)

        self.generate_fixtures(
            # https://www.openstreetmap.org/way/520091576
            dsl.way(520091576, wkt_loads(
                'POLYGON(('
                '-46.70706510543823242 -23.55252732329748255,'
                '-46.70701280236244202 -23.55263059139736015,'
                '-46.70701950788497925 -23.5526330501606509,'
                '-46.70699670910835266 -23.55267976665450647,'
                '-46.7069108784198761 -23.55264411459491214,'
                '-46.70686796307563782 -23.55272894189323551,'
                '-46.7070382833480835 -23.55280147533679269,'
                '-46.70707583427429199 -23.55272771251249253,'
                '-46.70710265636444092 -23.55273877693876727,'
                '-46.70713886618614197 -23.55266624346062088,'
                '-46.70714825391769409 -23.55266993160454092,'
                '-46.70719251036643982 -23.55258141612181078,'
                '-46.70706510543823242 -23.55252732329748255))'), {
                    'building': 'yes',
                    'height': '4.51',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520086815
            dsl.way(520086815, wkt_loads(
                'POLYGON(('
                '-46.70652061700820923 -23.5524621660022575,'
                '-46.7064763605594635 -23.55256666353558614,'
                '-46.70661851763725281 -23.55262690325233166,'
                '-46.70663058757781982 -23.55261706819842971,'
                '-46.70670568943023682 -23.55264903212093941,'
                '-46.70673251152038574 -23.55259370994242829,'
                '-46.70669630169868469 -23.55257772797541804,'
                '-46.70670703053474426 -23.55255559909480212,'
                '-46.70674458146095276 -23.5525691223000706,'
                '-46.70674726366996765 -23.55256297538875288,'
                '-46.70677542686462402 -23.55250642379121473,'
                '-46.70673251152038574 -23.55246462476868885,'
                '-46.70669093728065491 -23.5525445346531086,'
                '-46.70667082071304321 -23.55253838774063979,'
                '-46.706676185131073 -23.55252240576690781,'
                '-46.70652061700820923 -23.5524621660022575))'), {
                    'building': 'yes',
                    'height': '6.03',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520086785
            dsl.way(520086785, wkt_loads(
                'POLYGON((-46.7069457471370697 -23.55248429489859063,'
                '-46.70687064528465271 -23.55249412996244018,'
                '-46.70686528086662292 -23.55250396502553656,'
                '-46.70688673853874207 -23.5525138000879366,'
                '-46.70687198638916016 -23.55254330527063189,'
                '-46.70682236552238464 -23.55252240576690781,'
                '-46.70677945017814636 -23.55260969190750586,'
                '-46.70673385262489319 -23.55259125117839858,'
                '-46.70673251152038574 -23.55259370994242829,'
                '-46.70670032501220703 -23.55266009655385062,'
                '-46.70685186982154846 -23.55272525375096393,'
                '-46.70693099498748779 -23.55256789291783548,'
                '-46.70688539743423462 -23.55254945218285911,'
                '-46.70690149068832397 -23.55251871761882398,'
                '-46.70695245265960693 -23.55254084650566426,'
                '-46.70696988701820374 -23.55250888255683606,'
                '-46.7069457471370697 -23.55248429489859063))'), {
                    'building': 'yes',
                    'height': '3.31',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520086778
            dsl.way(520086778, wkt_loads(
                'POLYGON((-46.70694842934608459 -23.5521093325406099,'
                '-46.70686393976211548 -23.55218063694022135,'
                '-46.70697122812271118 -23.5522912816216774,'
                '-46.70699000358581543 -23.55227652900285307,'
                '-46.70701682567596436 -23.55230357546942344,'
                '-46.70702621340751648 -23.55229619916090655,'
                '-46.70704096555709839 -23.55231218116217917,'
                '-46.70700743794441223 -23.55234045700575507,'
                '-46.70703426003456116 -23.55236750345916619,'
                '-46.70705705881118774 -23.5523908617553559,'
                '-46.70711740851402283 -23.55234045700575507,'
                '-46.70705437660217285 -23.55227529961788946,'
                '-46.70708522200584412 -23.55225071191595987,'
                '-46.70704364776611328 -23.55220891281211948,'
                '-46.70705974102020264 -23.5521953895698033,'
                '-46.70702621340751648 -23.55216219615093109,'
                '-46.70701280236244202 -23.55217449001075636,'
                '-46.70694842934608459 -23.5521093325406099))'), {
                    'building': 'yes',
                    'height': '6.09',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520087792
            dsl.way(520087792, wkt_loads(
                'POLYGON((-46.70773833990097046 -23.55201098158111961,'
                '-46.70764848589897156 -23.55205401013495248,'
                '-46.70765653252601624 -23.55206753339182058,'
                '-46.70764312148094177 -23.55207368032631621,'
                '-46.70762702822685242 -23.55204540442530003,'
                '-46.70757874846458435 -23.55206876277873107,'
                '-46.70763909816741943 -23.55217571939667209,'
                '-46.70765787363052368 -23.55216711369500615,'
                '-46.70769408345222473 -23.55223104175111359,'
                '-46.70774504542350769 -23.55220645404089908,'
                '-46.70773431658744812 -23.55218801325523259,'
                '-46.70781612396240234 -23.55214867290379743,'
                '-46.70773833990097046 -23.55201098158111961))'), {
                    'building': 'yes',
                    'height': '5.46',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520091545
            dsl.way(520091545, wkt_loads(
                'POLYGON((-46.70750364661216736 -23.55166429386198956,'
                '-46.70743122696876526 -23.55169871679699156,'
                '-46.70743793249130249 -23.551708551919603,'
                '-46.70740172266960144 -23.55172576338243573,'
                '-46.70742854475975037 -23.5517737095884172,'
                '-46.7074151337146759 -23.55177985653662631,'
                '-46.70746877789497375 -23.55187451950293109,'
                '-46.70762166380882263 -23.5518019855478542,'
                '-46.70756801962852478 -23.55170609313901764,'
                '-46.70753583312034607 -23.55172207521201244,'
                '-46.70750364661216736 -23.55166429386198956))'), {
                    'building': 'yes',
                    'height': '5.76',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520090963
            dsl.way(520090963, wkt_loads(
                'POLYGON((-46.70716434717178345 -23.55230111669996518,'
                '-46.70711740851402283 -23.55234045700575507,'
                '-46.70705705881118774 -23.5523908617553559,'
                '-46.70710667967796326 -23.55244003710217271,'
                '-46.70712277293205261 -23.5524265138836455,'
                '-46.70726627111434937 -23.55257281044671913,'
                '-46.70734673738479614 -23.55250642379121473,'
                '-46.70729175209999084 -23.55245110155267696,'
                '-46.70727431774139404 -23.55246585415190452,'
                '-46.7072528600692749 -23.55244372525244501,'
                '-46.70726627111434937 -23.5524326608013439,'
                '-46.70720189809799194 -23.55236750345916619,'
                '-46.70712947845458984 -23.5524265138836455,'
                '-46.70710533857345581 -23.55240192620999551,'
                '-46.70717105269432068 -23.55234660392748935,'
                '-46.70716568827629089 -23.55234291577447436,'
                '-46.70718714594841003 -23.55232570439247297,'
                '-46.70716434717178345 -23.55230111669996518))'), {
                    'building': 'yes',
                    'height': '3.39',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520091551
            dsl.way(520091551, wkt_loads(
                'POLYGON((-46.70706376433372498 -23.55200729341869703,'
                '-46.70696720480918884 -23.55208843296787791,'
                '-46.7071080207824707 -23.55223104175111359,'
                '-46.70720458030700684 -23.55214867290379743,'
                '-46.70714825391769409 -23.55209089174130099,'
                '-46.70713886618614197 -23.55209949744798337,'
                '-46.70712143182754517 -23.55208105664729601,'
                '-46.70713081955909729 -23.55207490971315565,'
                '-46.70706376433372498 -23.55200729341869703))'), {
                    'building': 'yes',
                    'height': '6.37',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520091549
            dsl.way(520091549, wkt_loads(
                'POLYGON((-46.70718446373939514 -23.55193967708946445,'
                '-46.70710265636444092 -23.55200852280617596,'
                '-46.70727699995040894 -23.5521843250977696,'
                '-46.70726090669631958 -23.55219661895552008,'
                '-46.70727431774139404 -23.55220891281211948,'
                '-46.70732259750366211 -23.55216957246696552,'
                '-46.70727431774139404 -23.55212162640536633,'
                '-46.70732259750366211 -23.55208105664729601,'
                '-46.70718446373939514 -23.55193967708946445))'), {
                    'building': 'yes',
                    'height': '6.86',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520087793
            dsl.way(520087793, wkt_loads(
                'POLYGON((-46.7076323926448822 -23.55182042638769246,'
                '-46.70760422945022583 -23.55183394966859112,'
                '-46.70761629939079285 -23.55185607867068143,'
                '-46.70748621225357056 -23.55191877748976026,'
                '-46.70754924416542053 -23.5520318811661582,'
                '-46.70770883560180664 -23.55195565913406597,'
                '-46.7076323926448822 -23.55182042638769246))'), {
                    'building': 'yes',
                    'height': '5.5',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520091311
            dsl.way(520091311, wkt_loads(
                'POLYGON((-46.70752778649330139 -23.5520847448076438,'
                '-46.70743927359580994 -23.55215850799275756,'
                '-46.7075800895690918 -23.55230111669996518,'
                '-46.70765385031700134 -23.55223964744858733,'
                '-46.70762166380882263 -23.55220768342651638,'
                '-46.70763641595840454 -23.5521953895698033,'
                '-46.70752778649330139 -23.5520847448076438))'), {
                    'building': 'yes',
                    'height': '4.01',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520086782
            dsl.way(520086782, wkt_loads(
                'POLYGON((-46.70685455203056335 -23.55220522465526756,'
                '-46.7067660391330719 -23.55227775838783089,'
                '-46.7068183422088623 -23.55233185131487517,'
                '-46.70683175325393677 -23.55232078685433805,'
                '-46.70692160725593567 -23.55241176127999836,'
                '-46.70699670910835266 -23.55234906269608075,'
                '-46.70685455203056335 -23.55220522465526756))'), {
                    'building': 'yes',
                    'height': '3.2',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520090964
            dsl.way(520090964, wkt_loads(
                'POLYGON((-46.70733600854873657 -23.55231463993141006,'
                '-46.70728906989097595 -23.55235398023314985,'
                '-46.70728102326393127 -23.55234783331178505,'
                '-46.7072528600692749 -23.55237119161147064,'
                '-46.70726090669631958 -23.55237979729977837,'
                '-46.70725017786026001 -23.55238840298753189,'
                '-46.70736953616142273 -23.55251011193961119,'
                '-46.70745670795440674 -23.55243757833527241,'
                '-46.70733600854873657 -23.55231463993141006))'), {
                    'building': 'yes',
                    'height': '6.26',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520090966
            dsl.way(520090966, wkt_loads(
                'POLYGON((-46.70744463801383972 -23.5522003071126278,'
                '-46.70735880732536316 -23.55227284084789119,'
                '-46.70748084783554077 -23.55239700867470276,'
                '-46.70756667852401733 -23.55232570439247297,'
                '-46.70744463801383972 -23.5522003071126278))'), {
                    'building': 'yes',
                    'height': '6.69',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520086834
            dsl.way(520086834, wkt_loads(
                'POLYGON((-46.70675396919250488 -23.5522839053124784,'
                '-46.70665472745895386 -23.55236750345916619,'
                '-46.70674324035644531 -23.5524584778524968,'
                '-46.70677006244659424 -23.55243511956831526,'
                '-46.70678213238716125 -23.55244741340261783,'
                '-46.70683577656745911 -23.55240315559379383,'
                '-46.70676335692405701 -23.55232939254595692,'
                '-46.70678213238716125 -23.55231341054678751,'
                '-46.70675396919250488 -23.5522839053124784))'), {
                    'building': 'yes',
                    'height': '3.42',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520091546
            dsl.way(520091546, wkt_loads(
                'POLYGON((-46.70727163553237915 -23.55183272027947794,'
                '-46.70717641711235046 -23.5519126305480313,'
                '-46.70722201466560364 -23.55195688852202807,'
                '-46.70723274350166321 -23.55194828280603758,'
                '-46.70728102326393127 -23.55199868770600347,'
                '-46.70736551284790039 -23.55192861259591552,'
                '-46.70727163553237915 -23.55183272027947794))'), {
                    'building': 'yes',
                    'height': '5.78',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520090962
            dsl.way(520090962, wkt_loads(
                'POLYGON((-46.70705705881118774 -23.5523908617553559,'
                '-46.7069457471370697 -23.55248429489859063,'
                '-46.70699402689933777 -23.55253347021047716,'
                '-46.70710667967796326 -23.55244003710217271,'
                '-46.70705705881118774 -23.5523908617553559))'), {
                    'building': 'yes',
                    'height': '3.48',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520091543
            dsl.way(520091543, wkt_loads(
                'POLYGON((-46.70746207237243652 -23.55190156605220864,'
                '-46.70744463801383972 -23.55191017177126866,'
                '-46.70739904046058655 -23.5519310713723371,'
                '-46.70749157667160034 -23.5520269636170525,'
                '-46.70751839876174927 -23.55205646890902926,'
                '-46.7075425386428833 -23.55204540442530003,'
                '-46.70746207237243652 -23.55190156605220864))'), {
                    'building': 'yes',
                    'height': '5.52',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520091312
            dsl.way(520091312, wkt_loads(
                'POLYGON((-46.70749157667160034 -23.5520269636170525,'
                '-46.70741379261016846 -23.55209212112799833,'
                '-46.70738160610198975 -23.55211916763251168,'
                '-46.70739904046058655 -23.55213883781411255,'
                '-46.7074178159236908 -23.55215727860668551,'
                '-46.70746609568595886 -23.55211547947314443,'
                '-46.70746073126792908 -23.5521105619271367,'
                '-46.70752242207527161 -23.55205892768306342,'
                '-46.70751839876174927 -23.55205646890902926,'
                '-46.70749157667160034 -23.5520269636170525))'), {
                    'building': 'yes',
                    'height': '3.67',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520091309
            dsl.way(520091309, wkt_loads(
                'POLYGON((-46.70738160610198975 -23.55211916763251168,'
                '-46.70732259750366211 -23.55216957246696552,'
                '-46.70727431774139404 -23.55220891281211948,'
                '-46.70731455087661743 -23.55225071191595987,'
                '-46.7073802649974823 -23.55219661895552008,'
                '-46.70737087726593018 -23.55218678386941633,'
                '-46.70737624168395996 -23.55218063694022135,'
                '-46.70736417174339294 -23.55216834308097873,'
                '-46.70739904046058655 -23.55213883781411255,'
                '-46.70738160610198975 -23.55211916763251168))'), {
                    'building': 'yes',
                    'height': '5.02',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520085168
            dsl.way(520085168, wkt_loads(
                'POLYGON((-46.70696988701820374 -23.55255805785949974,'
                '-46.7069283127784729 -23.55263796768710449,'
                '-46.70698195695877075 -23.55266009655385062,'
                '-46.70702353119850159 -23.55258018673970355,'
                '-46.70696988701820374 -23.55255805785949974))'), {
                    'building': 'yes',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520091544
            dsl.way(520091544, wkt_loads(
                'POLYGON((-46.70742988586425781 -23.5518376378358596,'
                '-46.70734673738479614 -23.55187697828036164,'
                '-46.70739904046058655 -23.5519310713723371,'
                '-46.70744463801383972 -23.55191017177126866,'
                '-46.70743256807327271 -23.5518868133896575,'
                '-46.70745134353637695 -23.55187820766907691,'
                '-46.70742988586425781 -23.5518376378358596))'), {
                    'building': 'yes',
                    'height': '5.9',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520090961
            dsl.way(520090961, wkt_loads(
                'POLYGON((-46.70703426003456116 -23.55236750345916619,'
                '-46.70692294836044312 -23.55246093661901341,'
                '-46.7069457471370697 -23.55248429489859063,'
                '-46.70705705881118774 -23.5523908617553559,'
                '-46.70703426003456116 -23.55236750345916619))'), {
                    'building': 'yes',
                    'height': '3.106',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520086812
            dsl.way(520086812, wkt_loads(
                'POLYGON((-46.70688539743423462 -23.55242159634927646,'
                '-46.70683175325393677 -23.55246708353509177,'
                '-46.70685991644859314 -23.55249535934537164,'
                '-46.70687064528465271 -23.55249412996244018,'
                '-46.7069457471370697 -23.55248429489859063,'
                '-46.70692294836044312 -23.55246093661901341,'
                '-46.70688539743423462 -23.55242159634927646))'), {
                    'building': 'yes',
                    'height': '3.111',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520090965
            dsl.way(520090965, wkt_loads(
                'POLYGON((-46.70722737908363342 -23.55224825314552106,'
                '-46.70718580484390259 -23.55228267592757163,'
                '-46.70716434717178345 -23.55230111669996518,'
                '-46.70718714594841003 -23.55232570439247297,'
                '-46.7072179913520813 -23.55235643900162756,'
                '-46.7072179913520813 -23.55231709870061252,'
                '-46.70725956559181213 -23.55228144654265066,'
                '-46.70722737908363342 -23.55224825314552106))'), {
                    'building': 'yes',
                    'height': '3.73',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520091548
            dsl.way(520091548, wkt_loads(
                'POLYGON((-46.70735880732536316 -23.55203556932788445,'
                '-46.707325279712677 -23.55206261584402228,'
                '-46.70738160610198975 -23.55211916763251168,'
                '-46.70741379261016846 -23.55209212112799833,'
                '-46.70735880732536316 -23.55203556932788445))'), {
                    'building': 'yes',
                    'height': '4.14',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520087097
            dsl.way(520087097, wkt_loads(
                'POLYGON((-46.7068210244178772 -23.55250027687696956,'
                '-46.70677542686462402 -23.55250642379121473,'
                '-46.70674726366996765 -23.55256297538875288,'
                '-46.70678213238716125 -23.55257772797541804,'
                '-46.7068210244178772 -23.55250027687696956))'), {
                    'building': 'yes',
                    'height': '3.001',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520085150
            dsl.way(520085150, wkt_loads(
                'POLYGON((-46.70728504657745361 -23.55224948253075468,'
                '-46.70728102326393127 -23.55225071191595987,'
                '-46.70726090669631958 -23.55226546453768321,'
                '-46.70729577541351318 -23.55230480485414546,'
                '-46.70730516314506531 -23.55230972239286302,'
                '-46.70730918645858765 -23.55230849300819784,'
                '-46.70731857419013977 -23.55230603423883906,'
                '-46.70733198523521423 -23.5522925110064989,'
                '-46.70729711651802063 -23.55225317068637025,'
                '-46.70729175209999084 -23.55225071191595987,'
                '-46.70728504657745361 -23.55224948253075468))'), {
                    'building': 'yes',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520085140
            dsl.way(520085140, wkt_loads(
                'POLYGON((-46.70739367604255676 -23.55214621413145437,'
                '-46.70736685395240784 -23.55216834308097873,'
                '-46.70741111040115356 -23.55221260096887193,'
                '-46.70743793249130249 -23.55219047202680827,'
                '-46.70739367604255676 -23.55214621413145437))'), {
                    'building': 'yes',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520090960
            dsl.way(520090960, wkt_loads(
                'POLYGON((-46.70714020729064941 -23.55223595929260227,'
                '-46.70711874961853027 -23.55225562945670958,'
                '-46.70716434717178345 -23.55230111669996518,'
                '-46.70718580484390259 -23.55228267592757163,'
                '-46.70714020729064941 -23.55223595929260227))'), {
                    'building': 'yes',
                    'height': '3.07',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520085149
            dsl.way(520085149, wkt_loads(
                'POLYGON((-46.70722737908363342 -23.55217817816847514,'
                '-46.70721128582954407 -23.5521929307983271,'
                '-46.70721665024757385 -23.5522027658839761,'
                '-46.70721530914306641 -23.55221383035446081,'
                '-46.70721262693405151 -23.5522212066675678,'
                '-46.70719921588897705 -23.55223350052187925,'
                '-46.70721396803855896 -23.55224702376028745,'
                '-46.70725688338279724 -23.55221137158331146,'
                '-46.70722737908363342 -23.55217817816847514))'), {
                    'building': 'yes',
                    'source': 'openstreetmap.org',
                }),
            # https://www.openstreetmap.org/way/520085148
            dsl.way(520085148, wkt_loads(
                'POLYGON((-46.70734807848930359 -23.55209212112799833,'
                '-46.707325279712677 -23.55211302070016188,'
                '-46.70732393860816956 -23.55211793824607014,'
                '-46.70732393860816956 -23.55212408517819256,'
                '-46.7073427140712738 -23.5521425259728403,'
                '-46.70737221837043762 -23.55211916763251168,'
                '-46.70734807848930359 -23.55209212112799833))'), {
                    'building': 'yes',
                    'source': 'openstreetmap.org',
                }),
            )

        with self.features_in_tile_layer(z, x, y, 'buildings') as features:
            # have to use assertTrue here rather than the more natural
            # assertEqual so that when this is run as --download-only the test
            # case class can skip this test.
            self.assertTrue(len(features) == 1)
